package br.com.cfccultura.admin.view.tag.combo;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Component;

import br.com.cfccultura.admin.model.dao.IBancoDAO;
import br.com.cfccultura.admin.model.vo.Banco;
import br.com.cfccultura.admin.view.tag.combo.helper.BancoTagHelper;

@Component
public class ComboBancoTag extends DefaultComboTag {
	
	private static final long serialVersionUID = 1073435506129686702L;
	
	@Override
	public int doStartTagInternal() throws JspException {
		
		IBancoDAO dao = getBean(IBancoDAO.class);

		List<Banco> list = dao.consultar(new Banco());
		List<BancoTagHelper> helperList = new ArrayList<BancoTagHelper>();
		
		for(Banco banco : list) {
			BancoTagHelper helper = new BancoTagHelper();
			try {
				BeanUtils.copyProperties(helper, banco);
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
			helperList.add(helper);
		}
		
		buildCombo(helperList, "nome", "codigo");
		
		return SKIP_BODY;
	}
}
